"""typeidea URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""



from comment.views import CommentView
from django.contrib import admin
from django.contrib.sitemaps import views as sitemap_views
from django.urls import path,re_path
from django.conf.urls import url

from blog.rss import LatestPostFeed
from blog.sitemap import PostSitemap
#from blog.views import post_list,post_detail
from blog.views import (
    IndexView,CategoryView,TagView,PostDetailView,
    SearchView,AuthorView,
)
from config.views import LinkListView   #links,
from comment.views import CommentView
from .custom_site import custom_site

import xadmin
xadmin.autodiscover()
# version模块自动注册需要版本控制的 Model
from xadmin.plugins import xversion
xversion.register_models()

urlpatterns = [
    #path('',post_list,name='index'),
    #re_path(r'^category/(?P<category_id>\d+)/$',post_list),
    path('',IndexView.as_view(),name='index'),
    #path('category/<category_id>/',post_list,name='category-list'),
    #re_path(r'^tag/(?P<tag_id>\d+)/$',post_list),
    path('category/<category_id>/',CategoryView.as_view(),name='category-list'),             #3.0.3版本可这样写，简洁，不加/会导致最后一项或第一项无法打开
    #re_path('category/(?P<category_id>\d+)/$',CategoryView.as_view(),name='category-list'),#模仿书中url正则写法
    #path('tag/<tag_id>/',post_list,name='tag-list'),
    path('tag/<tag_id>/',TagView.as_view(),name='tag-list'),                                 #3.0.3版本可这样写，简洁
    #re_path('tag/(?P<tag_id>\d+)/$',TagView.as_view(),name='tag-list'),                    #模仿书中url正则写法
    #re_path(r'^post/(?P<post_id>\d+).html$',post_detail),
    #path('post/<post_id>.html/',post_detail,name='post-detail'),
    #re_path('post/(?P<pk>\d+).html$',PostDetailView.as_view(),name='post-detail'),
    path('post/<post_id>.html/',PostDetailView.as_view(),name='post-detail'),                 #3.0.3版本可这样写，不加/会导致第一篇文章详情页无法打开
    #re_path('post/(?P<post_id>\d+).html/',PostDetailView.as_view(),name='post-detail'),     #模仿书中url正则写法
    #path('links/',links,name='links'),
    path('super_admin/',admin.site.urls,name='super-admin'),
    path('admin/', custom_site.urls,name='admin'),
    path('search/',SearchView.as_view(),name='search'),
    path('author/<owner_id>/',AuthorView.as_view(),name='author'),
    path('links/',LinkListView.as_view(),name='links'),
    path('comment/',CommentView.as_view(),name='comment'),
    #url(r'^rss|feed/',LatestPostFeed(),name='rss'),
    path('feed/',LatestPostFeed(),name='rss'),
    path('rss/',LatestPostFeed(),name='rss'),
    #url(r'^sitemap\.xml$',sitemap_views.sitemap,{'sitemaps':{'posts':PostSitemap}}),#书中此写法不通
    path('sitemap.xml/',sitemap_views.sitemap,{'sitemaps':{'posts':PostSitemap}}),
    path('xadmin/',xadmin.site.urls),
]
#注意：上面的re_path是书上的正则写法

"""
    访问网址 http://127.0.0.1:8000/
    返回内容 post_list category_id=None,tag_id=None

    访问网址 http://127.0.0.1:8000/category/1/
    返回内容 post_list category_id=1,tag_id=None
    
    访问网址 http://127.0.0.1:8000/tag/1/
    返回内容 post_list category_id=None,tag_id=1

    访问网址 http://127.0.0.1:8000/post/2.html/
    返回内容 detail

    访问网址 http://127.0.0.1:8000/links/
    返回内容 links


"""